﻿using System.Collections.Generic;
using Microsoft.SharePoint;
using Repo.Interfaces;

namespace Repo.FieldTypes
{
    public class LookupMultiChoice : IComplexFieldType
    {
        public Dictionary<int, string> Choices { get; set; }

        public IComplexFieldType SetInstanceValue(object value)
        {
            if (value != null)
            {
                var valueAsLookup = ((SPFieldLookupValueCollection)value);
                var multiChoice = new LookupMultiChoice { Choices = new Dictionary<int, string>() };
                foreach (var spFieldLookupValue in valueAsLookup)
                {
                    multiChoice.Choices.Add(spFieldLookupValue.LookupId, spFieldLookupValue.LookupValue);
                }
                return multiChoice;
            }
            return null;
        }
    }
}
